#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Solution 
{
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) 
    {
        bool flag1[1001] = {false};
        bool flag2[1001] = {false};
        vector<int> result;
        for(int i = 0; i < nums1.size(); i++)
        {
            flag1[nums1[i]] = true;
        }
        for(int i = 0; i < nums2.size(); i++)
        {
            flag2[nums2[i]] = true;
        }
        for(int i = 0; i < 1001; i++)
        {
            if(flag1[i] && flag2[i])
            {
                result.push_back(i);
            }
        }
        return result;
    }
};

int main() {
    Solution sol;

    // 测试用例1：有交集
    vector<int> nums1_1 = {1, 2, 2, 1};
    vector<int> nums2_1 = {2, 2};
    vector<int> res1 = sol.intersection(nums1_1, nums2_1);
    cout << "测试用例1结果: ";
    for (int n : res1) cout << n << " ";
    cout << endl;

    // 测试用例2：无交集
    vector<int> nums1_2 = {1, 3, 5};
    vector<int> nums2_2 = {2, 4, 6};
    vector<int> res2 = sol.intersection(nums1_2, nums2_2);
    cout << "测试用例2结果: ";
    for (int n : res2) cout << n << " ";
    cout << endl;

    // 测试用例3：全部相同
    vector<int> nums1_3 = {7, 7, 7};
    vector<int> nums2_3 = {7, 7};
    vector<int> res3 = sol.intersection(nums1_3, nums2_3);
    cout << "测试用例3结果: ";
    for (int n : res3) cout << n << " ";
    cout << endl;

    // 测试用例4：有多个交集元素
    vector<int> nums1_4 = {1, 2, 3, 4, 5};
    vector<int> nums2_4 = {3, 4, 5, 6, 7};
    vector<int> res4 = sol.intersection(nums1_4, nums2_4);
    cout << "测试用例4结果: ";
    for (int n : res4) cout << n << " ";
    cout << endl;

    // 测试用例5：有空数组
    vector<int> nums1_5 = {};
    vector<int> nums2_5 = {1, 2, 3};
    vector<int> res5 = sol.intersection(nums1_5, nums2_5);
    cout << "测试用例5结果: ";
    for (int n : res5) cout << n << " ";
    cout << endl;

    return 0;
}
